package com.eascs.ticket.configuration.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eascs.common.assertion.util.AssertWarnUtils;
import com.eascs.ticket.common.service.BaseSevice;
import com.eascs.ticket.configuration.entity.ProjectCommentTemplate;
import com.eascs.ticket.configuration.entity.ProjectCommentTemplateUpdate;

@Service
public class ProjectCommentTemplateService extends BaseSevice {
	public List<Object[]> getAllProjectCommentTemplate() {
		return this.proxyDao.findObjectsList("sql.ProjectCommentTemplateService.getAllProjectCommentTemplate");
	}

	public ProjectCommentTemplate getProjectCommentTemplateByid(String id) {
		return this.proxyDao.getById(ProjectCommentTemplate.class, id);
	}

	@Transactional(transactionManager = "ticketTransactionManager")
	public ProjectCommentTemplate insertProjectCommentTemplate(ProjectCommentTemplate projectCommentTemplate) {
		this.proxyDao.insert(projectCommentTemplate);
		return projectCommentTemplate;
	}

	@Transactional(transactionManager = "ticketTransactionManager")
	public ProjectCommentTemplateUpdate updateProjectCommentTemplate(ProjectCommentTemplateUpdate projectCommentTemplateUpdate) {
		this.proxyDao.updateById(projectCommentTemplateUpdate);
		return projectCommentTemplateUpdate;
	}

	@Transactional(transactionManager = "ticketTransactionManager")
	public int deleteProjectCommentTemplateById(String id) {
		return this.proxyDao.deleteById(ProjectCommentTemplate.class, id);
	}

	public ProjectCommentTemplate findProjectCommentTemplate(String projectId, String ticketTypeCode, String statusId, String moduleId) {
		AssertWarnUtils.assertNotNull(projectId, "projectId must not null!");
		AssertWarnUtils.assertNotNull(ticketTypeCode, "ticketTypeCode must not null!");
		AssertWarnUtils.assertNotNull(statusId, "statusId must not null!");
		ProjectCommentTemplate projectCommentTemplate = new ProjectCommentTemplate();
		projectCommentTemplate.setProjectId(projectId);
		projectCommentTemplate.setStatusId(statusId);
		projectCommentTemplate.setTicketTypeCode(ticketTypeCode);
		projectCommentTemplate.setModuleId(moduleId);
		List<ProjectCommentTemplate> projectCommentTemplates = this.proxyDao.findEntitysWithAny(projectCommentTemplate);
		if (null == projectCommentTemplates || projectCommentTemplates.isEmpty())
			return null;
		else
			return projectCommentTemplates.get(0);
	}
}
